#include<iostream>
#include"RingBuffer.hpp"
#include<pthread.h>
#include<unistd.h>
using namespace RingBufferMoudle;
void*Consume(void*args)
{
    RingBuffer<int>*rq=static_cast<RingBuffer<int>*>(args);
    while(true)
    {
        int data;
        rq->Pop(&data);
        std::cout<<"消费者消费了："<<data<<std::endl;
    }
    return nullptr;
}
void*Product(void*args)
{
    RingBuffer<int>*bq=static_cast<RingBuffer<int>*>(args);

    int data=10;
    while(true)
    {
        sleep(2);
        bq->Push(data);
        std::cout<<"生产者生产了："<<data<<std::endl;
        ++data;
    }
    return nullptr;
}


int main()
{
    RingBuffer<int>*rq=new RingBuffer<int>(5);

    pthread_t c1,p1,c2,c3,p2;
    pthread_create(&c1,nullptr,Consume,rq);
    pthread_create(&c2,nullptr,Consume,rq);
    pthread_create(&c3,nullptr,Consume,rq);
    pthread_create(&p1,nullptr,Consume,rq);
    pthread_create(&p2,nullptr,Product,rq);


    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);
    pthread_join(c3,nullptr);
    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);


    return 0;
}